#include"stdafx.h"


WLResourcManager* g_pResourceManager = new WLResourcManager();
unsigned int ResIDCounter = 0;
void WLResourcManager::SetFileManager(WLFileManager* pFileManager)
{
	FileManager = pFileManager;
}

WLResource* WLResourcManager::LoadResource(EResType Type,char* ResPathName)
{
	if (!FileManager)
		return 0;
	WLResource* newRes = NULL;
	switch(Type)
	{
	case ERT_Mesh:
		newRes = new WLMesh();
		newRes = FileManager->LoadFileToResource(newRes,ResPathName);
		break;
	case ERT_BoneMesh:
		newRes = new WLBoneMesh();
		newRes = FileManager->LoadFileToResource( newRes, ResPathName );
		break;
	case ERT_BoneAnim:
		newRes = new WLBoneAnim();
		newRes = FileManager->LoadFileToResource( newRes, ResPathName );
		break;
	case ERT_Tex:
		break;
	}
	if ( newRes )
	{
		newRes->ID = ResIDCounter;
		Resources.push_back(newRes);
		ResIDCounter++;
	}
	return newRes;
}
WLResource* WLResourcManager::FindResourceByID( unsigned int ID )
{
	for ( unsigned int i = 0; i<Resources.size(); i++ )
	{
		if ( Resources[i]->ID == ID )
		{
			return Resources[i];
		}
	}
	return NULL;
}
WLResourcManager::~WLResourcManager()
{
	for ( unsigned i = 0; i<this->Resources.size(); i++ )
	{
		delete Resources[i];
		Resources[i] = NULL;
	
	}
	Resources.clear();
}